#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct students{
	long long ID;
	int score; 
	int exNum;
	int exRanking;
}Students;
Students student[105][305];
Students all[31000]; 
bool cmp(Students &a,Students &b){
	if(a.score==b.score)
		return a.ID<b.ID;
	return a.score>b.score;
}
int main(){
	int n,m,tail=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&m);
		for(int j=1;j<=m;j++){
			scanf("%lld %d",&student[i][j].ID,
			&student[i][j].score);
			student[i][j].exNum = i;
		}
		sort(student[i]+1,student[i]+m+1,cmp);
		int exr = 1;
		for(int j=1;j<=m;j++){
			if(j==1) student[i][j].exRanking = exr;
			else if(student[i][j].score==student[i][j-1].score)
				student[i][j].exRanking = exr;
			else {
				exr=j;
				student[i][j].exRanking = exr;
			}
			all[tail++] = student[i][j];
		}	
	}
	sort(all,all+tail,cmp);
	printf("%d\n",tail);
	int ranking=1;
	for(int i=0;i<tail;i++){
		printf("%lld ",all[i].ID);
		if(i==0)	printf("%d ",ranking);
		else if(all[i].score==all[i-1].score)
			printf("%d ",ranking);
		else{
			ranking = i+1;
			printf("%d ",ranking);
		}
		printf("%d %d\n",all[i].exNum,all[i].exRanking);
	}
		
	return 0;
}
